package com.lemon.utils.pay;

import java.util.Base64;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import com.lemon.utils.MD5;

public class AESUtil {
 
	/**
	 * 密钥算法
	 */
	private static final String ALGORITHM = "AES";
	/**
	 * 加解密算法/工作模式/填充方式
	 */
	private static final String ALGORITHM_MODE_PADDING = "AES/ECB/PKCS5Padding";
	/**
	 * 生成key
	 */
	private static SecretKeySpec key = new SecretKeySpec(MD5.getMD5(Constants.pay_key).toLowerCase().getBytes(),
			ALGORITHM);
 
	/**
	 * AES加密
	 * 
	 * @param data
	 * @return
	 * @throws Exception
	 */
	public static String encryptData(String data) throws Exception {
		// 创建密码器
		Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
		// 初始化
		cipher.init(Cipher.ENCRYPT_MODE, key);
		return Base64.getEncoder().encodeToString(cipher.doFinal(data.getBytes()));
	}
 
	/**
	 * AES解密
	 * 
	 * @param base64Data
	 * @return
	 * @throws Exception
	 */
	public static String decryptData(String base64Data) throws Exception {
		Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
		cipher.init(Cipher.DECRYPT_MODE, key);
		return new String(cipher.doFinal(Base64.getDecoder().decode(base64Data)));
	}
	public static void main(String[] args) throws Exception {
		//		String str = decryptData("E/O4RVCImj85Ubw8V6BIq/UaHifVD0YRCt9zYx6o+Ys2ImglaoCltU/bzDViw+/JiZOoLkB094+fpcOrIZpHDNuDPSK1FoAIu3mUB9N4XkACKuz3xfR/KP1/kuG8ocM5gUMUT1R7CL14omb3HtBlIlVsoEbM91v7xSUJ6YVrt8BjLzMlpzc+xe8/DfJVQV4T/qwrSZnDahvPDob8tZtAIPC3ISWZz9PyYTExf0onD0SMP/ZCVZ6IFRIRA+aHSU9tci5BnPyZ773tLqGjs3/kXPdLVuCbxLvDRRrA1PM/U43IGYazjSwcy+C4OFGphuqgsP8+FuY4PP4rJvTgytm0I7szG/Lx8qWpnKBJ1dRjFidj/gwRGy0Nf5tLGy7/NeWQOQ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